﻿Imports System.Runtime.InteropServices

Namespace OpenCL
    Public Class Kernel
        Public Property InternalPointer() As IntPtr
            Get
                Return m_InternalPointer
            End Get
            Private Set(ByVal value As IntPtr)
                m_InternalPointer = value
            End Set
        End Property
        Private m_InternalPointer As IntPtr

        Public Sub New(ByVal program As Program, ByVal functionName As String)
            Dim errorCode As Integer
            InternalPointer = OpenCLAPI.clCreateKernel(program.InternalPointer, functionName, errorCode)
        End Sub

        Protected Overrides Sub Finalize()
            Try
                OpenCLAPI.clReleaseKernel(InternalPointer)
            Finally
                MyBase.Finalize()
            End Try
        End Sub

        Public Sub SetArgument(ByVal argumentIndex As Integer, ByVal buffer As Buffer)
            Dim bufferPointer As IntPtr = buffer.InternalPointer
            OpenCLAPI.clSetKernelArg(InternalPointer, argumentIndex, Marshal.SizeOf(GetType(IntPtr)), bufferPointer)
        End Sub
    End Class
End Namespace